package br.com.portal.controllers;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import br.com.portal.DAO.ClienteDAO;
import br.com.portal.beans.Representante;

@WebServlet("/app/FillCli")
public class FillCli extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public FillCli() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession(false);
			if(request.getParameter("cliId")==null)
				request.setAttribute("clientes", ((Representante)session.getAttribute("rep")).consultarClientes());
			else
				request.setAttribute("clientes", ClienteDAO.getCliente(request.getParameter("clientes")));
			RequestDispatcher view = request.getRequestDispatcher("digitarpedido.jsp");
			view.forward(request, response);
	}

}
